package com.atguigu.eduservice.controller;
import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.service.EduVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-03-02
 */
@RestController
@RequestMapping("/eduservice/eduVideo")
@CrossOrigin
public class EduVideoController {

    @Autowired
    private EduVideoService videoService;

    //添加小节
    @PostMapping("addEduVideo")
    public R addEduVideo(@RequestBody EduVideo eduVideo){
        videoService.save(eduVideo);
        return R.ok();
    }

    //删除小节
    //TODO 后面这个方法需要完善，删除小节的时候，同时把里面视频删除
    @DeleteMapping("{id}")
    public R deletEduVideo(@PathVariable String id) {
        videoService.removeById(id);
        return R.ok();
    }

    //根据id查询出小节
    @GetMapping("getEduVideoInfo/{id}")
    public R getChapterInfo(@PathVariable String id)  {
        EduVideo byId = videoService.getById(id);
        return R.ok().data("eduVideo",byId);
    }

    //修改小节(修改之前要先根据id查询出小节)
    @PostMapping("updateEduVideo")
    public R updateChapter(@RequestBody EduVideo eduVideo){
        videoService.updateById(eduVideo);
        return R.ok();
    }


}

